<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>网络分析服务-服务区分析</title>
    <script type="text/javascript" src="../../dist/include-openlayers.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%">
<div id="map" style="width: 100%;height:100%"></div>
<script type="text/javascript">
    var map,
        baseUrl = (window.isLocal ? document.location.protocol + "//" + document.location.host : "http://support.supermap.com.cn:8090")+"/iserver/services/map-changchun/rest/maps/长春市区图",
        serviceUrl = (window.isLocal ? document.location.protocol + "//" + document.location.host : "http://support.supermap.com.cn:8090")+"/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
    var extent = [48.4, -7668.25, 8958.85, -55.58];
    var projection = new ol.proj.Projection({
        extent: extent,
        units: 'm'
    });
    new ol.supermap.MapService(baseUrl).getMapInfo(function (serviceResult) {
        var mapJSONObj = serviceResult.result;
        map = new ol.Map({
            target: 'map',
            controls: ol.control.defaults({attributionOptions: {collapsed: false}})
                .extend([new ol.supermap.control.Logo()]),
            view: new ol.View({
                center: [5105, -3375],
                zoom: 4,
                projection: projection
            })
        });
        var layer = new ol.layer.Tile({
            source: new ol.source.TileSuperMapRest(ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj))
        });
        map.addLayer(layer);
        findServiceAreas();
    });

    function findServiceAreas() {
        //添加待分析的中心点
        var point = new ol.geom.Point([5605, -3375]);
        var iconStyle = new ol.style.Style({
            image: new ol.style.Icon(({
                src: '../img/markerbig_select.png'
            }))
        });
        var feature = new ol.Feature(point);
        feature.setStyle(iconStyle);
        var pointSource = new ol.source.Vector({
            features: [feature]
        });
        var vectorLayer = new ol.layer.Vector({
            source: pointSource
        });
        map.addLayer(vectorLayer);

        var resultSetting = new SuperMap.TransportationAnalystResultSetting({
            returnEdgeFeatures: true,
            returnEdgeGeometry: true,
            returnEdgeIDs: true,
            returnNodeFeatures: true,
            returnNodeGeometry: true,
            returnNodeIDs: true,
            returnPathGuides: true,
            returnRoutes: true
        });
        var analystParameter = new SuperMap.TransportationAnalystParameter({
            resultSetting: resultSetting,
            weightFieldName: "length"
        });
        var parameter = new SuperMap.FindServiceAreasParameters({
            centers: [point],
            isAnalyzeById: false,
            parameter: analystParameter
        });
        parameter.weights = [400 + Math.random() * 100];

        new ol.supermap.NetworkAnalystService(serviceUrl).findServiceAreas(parameter, function (serviceResult) {
            var vectorSource = new ol.source.Vector({
                features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result.serviceAreaList[0].edgeFeatures)
            });
            var resultLayer = new ol.layer.Vector({
                source: vectorSource
            });
            map.addLayer(resultLayer);
        });
    }
</script>
</body>
</html>